﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gsl_runtime_sdk
{
    public class Variable
    {
        public enum var_type
        {
            Bool = 0x0001,
            Integer = 0x0010,
            Double = 0x0100,
            Float = 0x1000,
            String = 0x0011,
            Vector = 0x0101,
            UUID = 0x0111,
        }
        public static var_type GetType(string var)
        {
            int count = 0;
            bool p = var.Contains(".");
            bool f = var.Contains("f");
            if (p && f) return var_type.Float;
            else if (p) return var_type.Double;
            else if (var.Length >= 32 && var.Length <= 37 && var.LastIndexOf('-') == 21) return var_type.UUID;
            else if (var.Contains("true") || var.Contains("false")) return var_type.Bool;
            else if (var.Contains("<") && var.Contains(",")) return var_type.Vector;
            else
            {
                foreach (char chr in var)
                {
                    if (char.IsLetter(chr)) break;
                    else
                        count++;
                }
                if (count >= var.Length) return var_type.Integer;
                else return var_type.String;
            }
        }
        public Variable(string var)
        {
            Value = var;
            vtype = GetType(var);
        }
        public Variable()
        {

        }
        public void SetType()
        {
            vtype = GetType(val); //This Takes way to long, Need a faster method.
        }
        private string val;
        public string Value
        {
            get
            {
                return val;
            }
            set
            {
                vtype = GetType(value);// This Takes way to long, Need a faster method.
                val = value;
            }
        }

        public int start = 0;
        public int end = 0;
        public var_type vtype = new var_type();

        public int ToInteger()
        {
            return int.Parse(Value);
        }

        public float ToFloat()
        {
            return float.Parse(Value + "f");
        }

        public double ToDouble()
        {
            return double.Parse(Value);
        }

        public bool ToBool()
        {
            return bool.Parse(Value);
        }


        public static int ToInteger(string Value)
        {
            return int.Parse(Value);
        }

        public static float ToFloat(string Value)
        {
            return float.Parse(Value + "f");
        }

        public static double ToDouble(string Value)
        {
            return double.Parse(Value);
        }

        public static bool ToBool(string Value)
        {
            return bool.Parse(Value);
        }
    }
}
